/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package projeto.gui;

import javax.swing.JOptionPane;
import projeto.erro.GeralException;
import projeto.modelo.fachada.Fachada;
import projeto.modelo.to.NotaFiscal_Produto;

/**
 *
 * @author diego
 */
public class GuiNotaFiscal_AlterarProduto extends javax.swing.JDialog {
    
    Fachada fachada = new Fachada();
    public NotaFiscal_Produto nfpAlterar = new NotaFiscal_Produto();
    private NotaFiscal_Produto nfpNovo = new NotaFiscal_Produto();
    /**
     * Creates new form GuiNotaFiscal_AlterarProduto
     */
    public GuiNotaFiscal_AlterarProduto(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPalterarProduto = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        JcProdutoselecionado = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        JcMarca = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jQTDEField = new projeto.modelo.componente.SoNumero();
        jbalterar = new javax.swing.JButton();
        jPNF1 = new javax.swing.JPanel();
        jLNotaFiscalalt = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Alterar Qtde de Produto");

        jPalterarProduto.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel2.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        jLabel2.setText("Produto selecionado.:");

        JcProdutoselecionado.setBackground(new java.awt.Color(204, 204, 204));
        JcProdutoselecionado.setEditable(false);

        jLabel4.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        jLabel4.setText("Marca.:");

        JcMarca.setBackground(new java.awt.Color(204, 204, 204));
        JcMarca.setEditable(false);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("Quantidade.:");

        jbalterar.setText("Alterar");
        jbalterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbalterarActionPerformed(evt);
            }
        });

        jPNF1.setBorder(javax.swing.BorderFactory.createTitledBorder("Nota Fiscal"));

        jLNotaFiscalalt.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLNotaFiscalalt.setForeground(new java.awt.Color(0, 153, 0));
        jLNotaFiscalalt.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLNotaFiscalalt.setText("NF");

        javax.swing.GroupLayout jPNF1Layout = new javax.swing.GroupLayout(jPNF1);
        jPNF1.setLayout(jPNF1Layout);
        jPNF1Layout.setHorizontalGroup(
            jPNF1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPNF1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLNotaFiscalalt, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPNF1Layout.setVerticalGroup(
            jPNF1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLNotaFiscalalt)
        );

        javax.swing.GroupLayout jPalterarProdutoLayout = new javax.swing.GroupLayout(jPalterarProduto);
        jPalterarProduto.setLayout(jPalterarProdutoLayout);
        jPalterarProdutoLayout.setHorizontalGroup(
            jPalterarProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPalterarProdutoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPalterarProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPalterarProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPalterarProdutoLayout.createSequentialGroup()
                        .addComponent(jQTDEField, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jbalterar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPNF1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPalterarProdutoLayout.createSequentialGroup()
                        .addComponent(JcProdutoselecionado, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(JcMarca, javax.swing.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPalterarProdutoLayout.setVerticalGroup(
            jPalterarProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPalterarProdutoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPalterarProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPalterarProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4)
                        .addComponent(JcMarca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPalterarProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(JcProdutoselecionado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPalterarProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPalterarProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jQTDEField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jbalterar)
                        .addComponent(jLabel3))
                    .addComponent(jPNF1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(21, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPalterarProduto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPalterarProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbalterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbalterarActionPerformed
        // TODO add your handling code here:
        try{
            //Irei capturar alguns dados do antigo produto para poder altera
            nfpNovo.setProdutos_Codigo(nfpAlterar.getProdutos_Codigo());
            nfpNovo.setNotasFiscal_Numero(nfpAlterar.getNotasFiscal_Numero());
            nfpNovo.setNotasFiscalProdutos_Quantidade(Integer.parseInt(jQTDEField.getText()));
            
            fachada.atualizarNotaFiscal_Produto(nfpAlterar, nfpNovo);
            
            dispose();//fecha a janela
            
        }catch (GeralException ex){
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }
        

    }//GEN-LAST:event_jbalterarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GuiNotaFiscal_AlterarProduto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GuiNotaFiscal_AlterarProduto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GuiNotaFiscal_AlterarProduto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GuiNotaFiscal_AlterarProduto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the dialog
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                GuiNotaFiscal_AlterarProduto dialog = new GuiNotaFiscal_AlterarProduto(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JTextField JcMarca;
    public javax.swing.JTextField JcProdutoselecionado;
    public javax.swing.JLabel jLNotaFiscalalt;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPNF1;
    private javax.swing.JPanel jPalterarProduto;
    private javax.swing.JTextField jQTDEField;
    private javax.swing.JButton jbalterar;
    // End of variables declaration//GEN-END:variables
}
